#include<iostream>
#include<queue>
using namespace std;
int n;
int main()
{
	cin >> n;
	priority_queue<int, vector<int>, greater<int>>q;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		q.push(a);
	}
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		int p1 = q.top();
		q.pop();
		int p2 = q.top();
		q.pop();
		ans += p1 + p2;
		q.push(p1 + p2);
	}
	cout << ans << endl;
	return 0;
}